package face.test;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.File;
import java.io.IOException;


public class HttpClientFace {

	public static void main(String args[]) {

		String url = "https://api.megvii.com/facepp/v3/detect";
		HttpClient httpClient = new DefaultHttpClient();
		HttpPost httpPost = new HttpPost(url);

		try {
			File file = new File("F:\\9.png");

			FileBody fileBody = new FileBody(file);

			HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("image_file", fileBody)

					.addTextBody("api_key", "rE7V801GZWagS4FJzHoiAGu-AdECaK3q")
					.addTextBody("api_secret", "Up8GFjW_RMKT_QzZ3OmauFzdz2p132gR")
					.addTextBody("return_landmark", "1")
					.addTextBody("return_attributes", "gender,age")
					.build();

			httpPost.setEntity(reqEntity);

			HttpResponse response = httpClient.execute(httpPost);

			String content = EntityUtils.toString(response.getEntity());

			System.out.println(content);

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
